package ru.ifmo.croak.impl.ui.query.team1;

import ru.ifmo.croak.api.QueryService;
import ru.ifmo.croak.util.CroakFactory;

import javax.swing.*;

public class QueryUI implements Runnable{
    private QueryService queryService;

    public QueryUI(String name) {
        String queryProviderName = CroakFactory.getInstance().getProperty(name + ".provider");
        queryService = CroakFactory.getInstance().getImplementation(QueryService.class, queryProviderName);
    }
    private QueryUI() {

    }


    public void run() {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                MessagesModel messagesModel = new MessagesModel();
                SubscriptionsModel subscriptionsModel = new SubscriptionsModel(queryService, messagesModel);
                QueryUIForm queryUIForm = new QueryUIForm(subscriptionsModel);
                messagesModel.setEditorPane(queryUIForm.getjMessagesEditorPane());
                JFrame rootWindow = queryUIForm.getFrame();
                subscriptionsModel.setSubscriptionEditor(new SubscriptionEditor(rootWindow));
                rootWindow.setVisible(true);
            }
        });
    }

    public static void main(String[] args) {
        new QueryUI().run();
    }
}
